package com.int_tech.newTimeTask;

import com.int_tech.car.dao.CarDao;
import com.int_tech.car.dao.CarInfoDataDao;
import com.int_tech.car.entity.Car;
import com.int_tech.car.entity.CarInfoData;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.text.ParseException;
import java.util.List;

/**
 * Created by liubochao on 2018/6/26.
 */
@Component
public class CCarInfoDataTimeTask {

    @Autowired
    private CarInfoDataDao carInfoDataDao;

    @Autowired
    private CarDao carDao;

    @Scheduled(cron="0/10 * * * * ?")
    public void checkCCarInfoData() throws ParseException {

        List<CarInfoData> carInfoDataList = carInfoDataDao.findByStationId(0);

        List<Car> cars = carDao.findCarByIsDel(0);

        for (CarInfoData carInfoData : carInfoDataList)
        {
            for(Car car : cars)
            {
                if(car.getCarNumber().equals(carInfoData.getCarNumber()))
                {
                    carInfoData.setStationId(car.getStationId());
                    carInfoDataDao.save(carInfoData);
                    break;
                }
            }
        }
    }
}
